<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>


    <script>
        var map = new Map();
        //添加元素
        map.set('a',1);
        map.set('b',2);
        map.set('c',3);
        map.set('d',4);

        console.log(map);
        //获取map的大小
        console.log(map.size);

        //遍历  for-each

    map.forEach((key,value) =>{
        console.log(key + ":" + value)
    });


    console.log("**************************");
    // for of遍历
    //item把map的key和value转化成了数组，数组索引为0为map的key
    // 数组索引1的为map的value
    for (const item of map) {
        console.log(item[0] + ":" + item[1]);
    }

    console.log("**************************");
    //获取map的key
    for (const key of map.keys()) {
        console.log(map.get(key))
    }


    console.log("**************************");

    for (const value of map.values()) {
        console.log(value);
    }

    //通过entries
    for (const [k,v] of map.entries()) {
        console.log(k + ":" + v);
    }
    </script>

</body>

</html>